Skip to content

Keep worktree session dir when pane cwd is outside#49

Open
iam-vipin wants to merge 1 commit into
Ataraxy-Labs:mainfrom
iam-vipin:fix/worktree-session-dir
Open

Keep worktree session dir when pane cwd is outside#49
iam-vipin wants to merge 1 commit into
Ataraxy-Labs:mainfrom
iam-vipin:fix/worktree-session-dir

Conversation

@iam-vipin

Copy link
Copy Markdown

Summary

  • keep the tmux session path when the active pane cwd is outside that session path
  • still allow active pane subdirectories inside the session path to refine the displayed directory
  • add focused tests for both cases

Why

Worktree sessions can contain panes whose current directory points at a sibling/root checkout. Previously that active pane cwd could override the session's worktree path, causing branch/worktree metadata to be computed from the wrong directory.

Test

  • cargo test -p opensessions-runtime tmux_provider::tests::session_dir_
  • cargo fmt --check

@inspect-review inspect-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inspect review

Triage: 7 entities analyzed | 0 critical, 0 high, 3 medium, 4 low
Verdict: standard_review

Findings (4)

  1. [low] Logic error in is_home_dir: The function returns false when HOME environment variable is not set, but should handle the case where HOME exists but comparison fails. The current implementation using is_ok_and will return false both when HOME is unset AND when HOME is set but doesn't match, making it impossible to distinguish between these cases. More critically, if HOME is not set, the function silently returns false, which could cause incorrect behavior in choose_session_dir where it might incorrectly prefer active_dir over session_dir.
  2. [low] Path comparison bug in choose_session_dir: Using Path::new(active_dir).starts_with(Path::new(session_dir)) for path prefix checking is incorrect because starts_with does component-wise comparison, not string prefix. For example, /repo-wt/workspace-1 does NOT start with /repo-wt/workspace (different components), but /repo-wt/workspace-1/sub DOES start with /repo-wt/workspace-1. However, the test case expects /repo/packages/app to NOT be considered as starting with /repo-wt/workspace-1, which works correctly. But edge cases like /repo-wt/workspace-1x vs /repo-wt/workspace-1 would incorrectly return false when they should (string-wise they share a prefix but component-wise they don't). This is actually correct behavior for the intended use case, so this may not be a bug. Retracting this.
  3. [low] Logic error in is_home_dir: The function checks is_ok_and() but doesn't handle the case where HOME is not set. If HOME is not set, is_ok_and returns false, which means a directory won't be considered a home directory even if it should be. More critically, the function will return false for any directory when HOME is unset, which could lead to incorrect behavior in choose_session_dir where session_dir might actually be a home directory but isn't detected as such.
  4. [low] Path comparison logic error in choose_session_dir: The function uses Path::new(active_dir).starts_with(Path::new(session_dir)) which has a known footgun in Rust - starts_with() does component-wise comparison, not string prefix matching. For example, Path::new('/repo-wt/workspace-1').starts_with('/repo-wt/workspace') would return false even though the string starts with that prefix. This could cause the function to incorrectly return session_dir when it should return active_dir for paths that are actually subdirectories.

Reviewed by inspect | Entity-level triage found 0 high-risk changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant